﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CloudDrive.S3
{
    public class S3File
    {
        private string RemoveStartingSlash(string keyName)
        {
            if (keyName.StartsWith("\\"))
                return keyName.Substring(1);
            return keyName;
        }
        private bool IsValidS3KeyName(string keyName)
        {
            var utf8Key = ASCIIEncoding.UTF8.GetBytes(keyName);
            return utf8Key.Length <= 128;
        }
        public string RemoteFilePath { get; private set; }
        public FileOptions Options { get; private set; }
        public string LocalFilePath { get; private set; }
        public FileStream LocalFileStream { get; private set; }
        public bool IsDirectory
        {
            get
            {
                return RemoteFilePath.EndsWith("\\");
            }
        }
        public S3File(string fileName, FileOptions options)
        {
            fileName = RemoveStartingSlash(fileName);
            if (!IsValidS3KeyName(fileName))
                throw new ArgumentException("Filename must be less than 128 bytes in UTF8");
            Options = options;
            RemoteFilePath = fileName;
        }
    }
}
